﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web;
using System.IO;
using umbraco.BusinessLogic;

namespace uREST.Core
{
    public class uRESTConfig
    {
        public const string BaseUrl = "/rest";

        public static XmlNode GetConfigSection(string sectionName)
        {
            var configPath = HttpContext.Current.Server.MapPath("/config/uREST.config");

            if (File.Exists(configPath))
            {
                var configXml = new XmlDocument();
                configXml.Load(configPath);

                var section = configXml.SelectSingleNode("/uREST/" + sectionName);
                if (section != null)
                    return section;
                
                Log.Add(LogTypes.Custom, -1, "uREST: No " + sectionName + " config section found");
            }
            else
            {
                Log.Add(LogTypes.Error, -1, "uREST: Config not found");
            }

            return null;
        }
    }
}
